<template>
  <!-- 添加或修改项目基础信息管理对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body v-dialogDrag width="90%">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="98px">
      <el-form-item label="工程名称" prop="gongchengName">
        <el-input v-model="queryParams.gongchengName" placeholder="请输入工程名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品编码" prop="goodsCode">
        <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品型号" prop="model">
        <el-input v-model="queryParams.model" placeholder="请输入产品型号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品明细" prop="brand">
        <el-input v-model="queryParams.brand" placeholder="请输入产品明细"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="是否自制" prop="isdo">
        <el-select v-model="queryParams.isdo" placeholder="是否自制" clearable style="width: 130px">
          <el-option v-for="dict in dict.type.isdo"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading"
              show-summary :summary-method="getSummaries"  :max-height="maxHeight"
              @sort-change="handleSortChange">
        <el-table-column align="center" label="序号" type="index" width="50">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column sortable label="订单编码" align="center" prop="projectNo" show-overflow-tooltip/>
        <el-table-column sortable label="工程名称" align="center" prop="gongchengName" show-overflow-tooltip/>
        <el-table-column sortable label="产品编码" align="center" prop="goodsCode"/>
        <el-table-column sortable label="产品状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.goods_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column align="center" sortable label="工序分配状态" prop="state">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sale_state" :value="scope.row.state"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="产品名称" sortable prop="goodsName" show-overflow-tooltip/>
        <el-table-column align="center" label="合同物料名称" prop="contractGoodsName" show-overflow-tooltip/>
        <el-table-column align="center" label="产品型号" sortable prop="goodModel"/>
        <el-table-column align="center" label="产品单位" prop="unit"/>
        <el-table-column align="center" label="不含税单价" prop="goodsUnitPrice"/>
        <el-table-column align="center" label="含税单价" prop="goodsTaxUnitPrice"/>
        <el-table-column align="center" label="订单数量" prop="orderCount"/>
        <el-table-column align="center" label="不含税总价" prop="goodsTotalPrice"/>
        <el-table-column align="center" label="含税总价" prop="goodsTaxTotalPrice"/>
        <el-table-column align="center" sortable prop="deliveryTime" label="需求日期"  width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" sortable label="锁定数量" prop="lockCount"/>
        <el-table-column align="center" sortable label="剩余发货" prop="fahuoShengyu"/>
        <el-table-column label="是否自制" sortable align="center" prop="isdo">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.isdo" :value="scope.row.isdo"/>
          </template>
        </el-table-column>
        <el-table-column align="center" sortable label="自制/请购数量" prop="pleaseBuyCount"/>
        <el-table-column align="center" label="变更记录" prop="modifyremark" show-overflow-tooltip />
        <el-table-column align="center" label="备注" prop="remark" show-overflow-tooltip />

    </el-table>
    <pagination :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
      @pagination="getList" v-show="total>0"/>
    <div class="dialog-footer" slot="footer">
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {accAdd, addAction, deleteAction, getAction, getById} from '@/api/manage'
import ChoseGxForm from "./ChoseGxForm";
import ChajieForm from "./ChajieForm";
import FpTaskFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/FpTaskFormList";
import XunjianForm from "@/views/develop/projectBaseInfo/prjForGoodsIn/XunjianForm";
import FactoryTestQuality from "@/views/develop/factory/factoryTestQuality/FactoryTestQuality.vue";
import YongliaoMingxiFormList from '@/views/develop/goodsSaleMaterial/module/YongliaoMingxiFormList'
import FactoryTestQualityGoods from "@/views/develop/factory/factoryTestQuality/FactoryTestQualityGoods.vue";
import AddGoodsAgainForm from '@/views/develop/projectBaseInfo/module/AddGoodsAgainForm.vue';
import EditGoodsForm from '@/views/develop/projectBaseInfo/module/EditGoodsForm.vue';  // 引入 EditGoodsForm 组件
import EditRemarkForm from '@/views/develop/projectBaseInfo/module/EditRemarkForm.vue';
import EditGoodsTuihuiForm from '@/views/develop/projectBaseInfo/module/EditGoodsTuihuiForm.vue';
import ShengchanDoGoodsSaleForm from '@/views/develop/goodsSale/module/ShengchanDoGoodsSaleForm.vue';

export default {
    name: "AllGoodsFormShowList",
    dicts: ['isdo','sale_state','goods_status'],
    components: {
    },
    data() {
            return {
              maxHeight: (window.innerHeight * 0.9 - 260) ,
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "订单1产品明细",
                // 是否显示弹出层
                open: false,
                // 显示搜索条件
                showSearch: true,
                // 表单参数
                form: {},
                proId: "",
                proStatus: "",
                columns: [],
                projectColumns: [],
                total: 0,
                // 表单校验
                rules: {
                },
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    id: null,
                    code: null,
                    projectNo: null,
                    goodsName: null,
                    goodsCode: null,
                    model: null,
                    brand: null,
                    isdo: null,
                    remark: null,
                    projectId: null,
                    orderByColumn:"sort",
                    isAsc:"asc"
                },
                url: {
                    list: '/goodsSale/goodsSale/listAndFour',
                    getById: '/projectBaseInfo/projectBaseInfo/',
                },
            };
        },
        created() {
          //this.handleQuery();
        },
          methods: {
             /** 排序触发事件 */
            handleSortChange(column, prop, order) {
              this.queryParams.orderByColumn = column.prop;
              this.queryParams.isAsc = column.order;
              this.handleQuery();
            },
            shedingGygx(row){
              this.open = true;
              this.proId=row.id;
              this.projectColumns=row;
              this.getList();
            },
            getList() {
                this.loading = true;
                this.queryParams.projectId = this.proId;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.columns = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
              this.queryParams.pageNum = 1;
              this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
              this.resetForm("queryForm");
              this.handleQuery();
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
          reset() {
            this.form = {
              id: null,
              remark: null,
              delFlag: null,
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null
            };
            this.resetForm("form");
           },
            getSummaries(param) {
              // console.log(param);
              const {columns, data} = param;
              const sums = [];
              columns.forEach((column, index) => {
                if (index === 0) {
                  sums[index] = "合计";
                  return;
                }
                const values = data.map((item) => Number(item[column.property]));
                // 只合计amount1和amount3，想合并哪些列就在这里指定
                if ( column.property === "orderCount" || column.property === "goodsTotalPrice" || column.property === "goodsTaxTotalPrice" || column.property === "pleaseBuyCount" || column.property === "fahuoShengyu" || column.property === "lockCount") {
                  sums[index] = values.reduce((prev, curr) => {
                    const value = Number(curr);
                    if (!isNaN(value)) {
                      return accAdd(prev , curr);
                    } else {
                      return prev;
                    }
                  }, 0);
                }
              });
              return sums;
            },
        }
    };
</script>

